class _plugin(type):
	def __init__(self, name, bases, attrs):
		if not hasattr(self, 'plugins'):
			self.plugins = []
		else:
			self.plugins.append(self())

class plugin():
	__metaclass__ = _plugin
	
	@property
	def _irc(self):
		return self.__metaclass__.irc
	
	@property
	def _db(self):
		if 'database' in self._mods:
			return self._mods['database']
		return None

	@property
	def _mods(self):
		list = {}
		for plug in self.plugins:
			list[plug.__module__.split('.')[-1]] = plug
		return list

	@property
	def _funcs(self):
		list = {}
		for plug in self.plugins:
			for method in dir(plug):
				if not method.startswith('_') and hasattr(getattr(plug, method), '__call__'):
					list[method] = getattr(plug, method)
		return list
